#include <mosquittopp.h>
#include <string>
#include <iostream>
#include <functional>

class MqttClient : public mosqpp::mosquittopp {
public:
    using MessageCallback = std::function<void(const std::string& topic, const std::string& message)>;
    using MessageSubscription = std::function<void()>;

    MqttClient(const std::string& clientId, const std::string& host, int port = 1883);

    ~MqttClient();

    void setMessageCallback(MessageCallback cb);
    void setMessageSubscription(MessageSubscription sub);

    void subscribeTopic(const std::string& topic, int qos = 0);

    void publishMessage(const std::string& topic, const std::string& message, int qos = 0, bool retain = false);
    

protected:
    void on_connect(int rc) override;

    void on_disconnect(int rc) override ;

    void on_message(const struct mosquitto_message* message) override;

private:
    std::string host_;
    int port_;
    MessageCallback callback_;
    MessageSubscription MessageSub_;
};
